﻿using B.S.DataBase.MyProject.Domain.wdx;
using B.S.DataBase.MyProject.Domain.基础设置;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure;
using MediatR;
<<<<<<<< HEAD:MedicalPCTerminal.Read.API/Appcation/CommandHandlers/DoctorMovingCommandHandler/ResidentFilesmoveQueryCommandHandler.cs
using MedicalPCTerminal.Read.API.Appcation.Commands.DiagnosisTreatmentCommand;

namespace MedicalPCTerminal.Read.API.Appcation.CommandHandlers.DoctorMovingCommandHandler
========
using MedicalPCTerminal.Read.API.Appcation.Commands.医护移动端;

namespace MedicalPCTerminal.Read.API.Appcation.CommandHandlers.医护移动端
>>>>>>>> parent of fe317f5 (修改命名空间):MedicalPCTerminal.Read.API/Appcation/CommandHandlers/医护移动端/ResidentFilesmoveQueryCommandHandler.cs
{
    /// <summary>
    /// 医护移动端患者信息处理方法
    /// </summary>
    public class ResidentFilesmoveQueryCommandHandler : IRequestHandler<ResidentFilesmoveQueryCommand, ApiPaging<List<ResidentFiles>>>
    {

        /// <summary>
        /// sqlsugar
        /// </summary>

        private readonly SqlSugarContext sugar;

        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="sugar"></param>
        public ResidentFilesmoveQueryCommandHandler(SqlSugarContext sugar)
        {
            this.sugar = sugar;
        }

        /// <summary>
        /// 处理方法
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<ApiPaging<List<ResidentFiles>>> Handle(ResidentFilesmoveQueryCommand request, CancellationToken cancellationToken)
        {
            ApiPaging<List<ResidentFiles>> result = new ApiPaging<List<ResidentFiles>>();
            try
            {
                var list = sugar.db.Queryable<ResidentFiles>();
                if (!string.IsNullOrEmpty(request.ResidentFiles_Name))
                {
                    list = list.Where(x => x.ResidentFiles_Name.Contains(request.ResidentFiles_Name));
                }
                if (!string.IsNullOrEmpty(request.Phone))
                {
                    list = list.Where(x => x.Phone.Contains(request.Phone));
                }
                result.TotalCount=list.Count();
                var totalcount=list.Count();
                list = list.OrderByDescending(x => x.ResidentFiles_Id);
                result.data = list.ToList();
                result.Code = APIEnum.查询成功;
                result.Msg = APIEnum.查询成功.ToString();
            }
            catch (Exception ex)
            {
                // 记录异常信息
                Console.WriteLine($"添加团队信息时发生异常: {ex.Message}");
                result.Code = APIEnum.查询失败;
                result.Msg = APIEnum.查询失败.ToString();
            }
            return await Task.FromResult(result);
        }
    }
}
